<?php
namespace Summer\Sms\Classes;

use Overtrue\EasySms\Contracts\MessageInterface;
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
use Overtrue\EasySms\Gateways\Gateway;
use Overtrue\EasySms\Support\Config;
use Overtrue\EasySms\Traits\HasHttpRequest;

class QiruiGateway extends Gateway
{

    use HasHttpRequest;

    const ENDPOINT_HOST = 'http://api.qirui.com:7891';

    const ENDPOINT_URI = '/mt';

    protected $api_key;

    protected $api_secret;

    protected $sign = null;

    protected $client;

    /**
     * Send a short message.
     *
     * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
     * @param \Overtrue\EasySms\Contracts\MessageInterface $message
     * @param \Overtrue\EasySms\Support\Config $config
     *
     * @return array
     */
    public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
    {
        $params = [
            'un' => $config->get('api_key'),
            'pw' => $config->get('api_secret'),
            'sm' => '【' . $config->get('sign') . '】'.$message->getContent(),
            'da' => $to->getNumber(),
            'dc' => 15,
            'tf' => 3,
            'rf' => 2,
        ];

        return $this->post(self::ENDPOINT_URI, $params);
    }

    protected function getBaseUri()
    {
        return self::ENDPOINT_HOST;
    }


}
